TreeGrid Master / Detail Tutorial
4. Master detail tables
Master detail relation in plain tables
-
Plain master detail relation is used to show the same data in two or more grids in different layout.
Master grid shows the data in rows and detail grid shows the one master row data in different structure, often vertically in column.
-
The data are defined only in master grid, only master grid stores the changes and can upload them back to server.
Detail grid defines only layout, the columns and fixed (summary) rows and optionally variable rows shown only when the detail grid is empty (does not show any master row).
-
The master relation is defined usually in master default row <D> definition.
This default row defines attributes for all the master root rows and also their hidden children to be displayed in detail grid.
-
The default row name should not be 'R', because it will be used for the children by default.
The default row name can be set to <Root CDef/> attribute value to be used for all existing and new root rows in master grid.
-
The <D> has set its attribute
Detail
as id of the detail grid where the row's children will be shown. The Detail marks the row as master row.
It should have set also Expanded='0' CanExpand='0' to never show its chilren in master grid.
-
The <D> cell attributes
CopyTo
will define which master cells will be copied to which detail row(s) and cells.
Usual value of the master CopyTo attribute is "Child_X,Y", where X is child row position from 0 and Y is column name.
For example NAMECopyTo='Child_2,VALUE' means that master row's NAME cell will be copied to the third child row, to the cell name VALUE.
-
The <D> defines children that will be shown in detail grid. Defines them as nested <I> tags.
These child rows will be shown in detail grid, so they define cells in detail grid columns, not in master's.
These <I> tags can have any standard row or cell attribute, also Def attribute to specify row default.
-
The child row cell attributes
CopyTo
will define which detail cells will be copied to which master cells.
Usual value of the child CopyTo attribute is "Parent,Y", where Y is the master cell name.
For example VALUECopyTo='Parent,NAME' means that child row's VALUE cell will be copied to the master row's cell NAME.
-
How it works
-
On master grid load there will be created hidden children for every row according to the <D> definition.
To these children attributes will be copied values from the root rows, according to the <D> CopyTo attributes.
-
When some row in master grid is chosen to show it in detail grid (e.g. focused), all the row's children are copied from master grid to detail grid and here are shown.
In this time are all the child rows at two placed (in master grid and in detail grid) and all changes are synchronized and mirrored to both.
-
When a user changes some value in master grid, in root row, the change is automatically copied to its hidden children and also mirrored to detail grid.
It is done by CopyTo attribute in <D> tag, similarly to the grid loading.
-
When a user changes some value in detail grid, the change is mirrored to hidden child in master grid and also copied to the parent row.
It is done by CopyTo attribute in <D> child <I> tag.
-
When a user chooses another row in master grid to show it in detail grid, all actual detail grid variable rows are cleared and filled by the new content.
-
The behavior of choosing master row to show in detail row can be controlled by assigning ShowDetail action to appropriate event.
Or simply by Cfg attribute DetailOn - 0 – disabled, 1 – on focus to row, 2 – on click to row, 3 – on double click to row.
-
API
On showing the master row in detail grid is called API event OnShowDetail.
After the row is shown is called OnShowDetailFinish.
To manually show some master row in detail grid call API method ShowDetail.
To refresh or clear detail grid call RefreshDetail.